<template>
  <div id="Shenghuohui">
    <el-button style="float:right" type="success" icon="el-icon-share" @click="showLct">流程图</el-button>
    <el-dialog title="流程图" v-if="lctVisible" :visible.sync="lctVisible" width="98%" top="20px">
      <div style="min-height:900px"><liuchengtu :timestamp="liuchengtutimestamp"></liuchengtu></div>
    </el-dialog>
    <el-button style="float:right;margin-right:20px" type="success" icon="el-icon-goods" v-if="IsOperationUser" @click="showCaozuo">工作任务</el-button>
    <el-dialog title="工作任务" :visible.sync="caozuoVisible" width="98%" top="20px">
      <optform @refreshevent="caozuofinish" :timestamp="caozuotimestamp"></optform>
    </el-dialog>
    <el-button style="float:right;margin-right:20px" type="success" icon="el-icon-upload" @click="Fanganshow" v-if="IsOperationUser&&Operation==='FangAn'">上传工作方案</el-button>
    <el-dialog title="上传工作方案" :visible.sync="FangAnVisible" width="98%" top="20px">
      <FangAn :fileList="fileList" :timestamp="fangantimestamp" @refreshevent="uploadfinish"></FangAn>
    </el-dialog>
    <el-button style="float:right;margin-right:20px" type="success" icon="el-icon-upload" @click="Zhixingshow" v-if="IsOperationUser&&Operation==='ZhiXing'">上传会议数据</el-button>
    <el-dialog title="上传会议数据" :visible.sync="ZhixingVisible" width="98%" top="20px">
      <ZhiXing :operation="Operation" :havehuiyidata="HaveHuiYiData" @refreshevent="uploadfinish"></ZhiXing>
    </el-dialog>
    <el-button style="float:right;margin-right:20px" type="success" icon="el-icon-upload" @click="Pinggushow" v-if="IsOperationUser&&Operation==='ZhengGai'">上传评估整改数据</el-button>
    <el-dialog title="上传评估整改数据" :visible.sync="PingguVisible" width="98%" top="20px">
      <ZhiXing :operation="Operation" @refreshevent="uploadfinish"></ZhiXing>
    </el-dialog>
    <el-breadcrumb separator-class="el-icon-arrow-right" style="padding-bottom:20px;font-size:16px;">
      <el-breadcrumb-item :to="{ name: 'Shenghuohui' }">民主生活会</el-breadcrumb-item>
      <el-breadcrumb-item v-if="shenghuohuinameshow" :to="{ name: 'ShenghuohuiDetail', params: {id: shenghuohui.ShenghuohuiId}}">{{shenghuohui.ShenghuohuiName}}</el-breadcrumb-item>
      <el-breadcrumb-item>{{shenghuohui.UnitName}}</el-breadcrumb-item>
    </el-breadcrumb>
    <el-tabs v-model="activeName" type="border-card" style="margin-top:20px" @tab-click="tabClick">
      <!-- <el-tab-pane label="当前任务" name="Caozuo" v-if="IsOperationUser">
        <h1>当前任务描述：{{OperationMsg}}</h1>
        <div v-if="IsFinished === false">
          <FangAn v-if="showFangAn" :fileList="fileList" :timestamp="fangantimestamp"></FangAn>
          <ZhiXing v-if="showZhiXing"></ZhiXing>
          <hr style="height:1px;border:0;margin:30px 0;background:#999;overflow:hidden">
          <optformJieguo :myhouxuanren="Houxuanren" @refreshevent="getUnitDetails" v-if="CanBack"></optformJieguo>
          <optform :myhouxuanren="Houxuanren" @refreshevent="getUnitDetails" v-else></optform>
        </div>
      </el-tab-pane> -->
      <el-tab-pane name="Huiqian">
        <span slot="label">会前 <i class="el-icon-caret-right"></i></span>
        <Huiqian :timestamp="huiqiantimestamp"></Huiqian>
      </el-tab-pane>
      <el-tab-pane name="Huishang">
        <span slot="label">会中 <i class="el-icon-caret-right"></i></span>
        <Huishang :timestamp="huishangtimestamp"></Huishang>
      </el-tab-pane>
      <el-tab-pane name="Huihou">
        <span slot="label">会后 <i class="el-icon-caret-right"></i></span>
        <Huihou :timestamp="huihoutimestamp"></Huihou>
      </el-tab-pane>
      <el-tab-pane label="附件" name="Fujian">
        <Fujian :timestamp="fujiantimestamp"></Fujian>
      </el-tab-pane>
      <el-tab-pane label="质量评估" name="Pingjia">
        <Pingjia :timestamp="pingjiatimestamp"></Pingjia>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import pdf from 'vue-pdf'
import Pdfviewer from '@/components/Pdfviewer.vue'
import optformJieguo from '@/components/Optform_jieguo.vue'
import optform from '@/components/Optform.vue'
import FangAn from '@/components/Fangan.vue'
import ZhiXing from '@/components/Zhixing.vue'
import Huiqian from '@/Shenghuohui/Showdata/Huiqian.vue'
import Huishang from '@/Shenghuohui/Showdata/Huishang.vue'
import Huihou from '@/Shenghuohui/Showdata/Huihou.vue'
import Fujian from '@/Shenghuohui/Showdata/Fujian.vue'
import Pingjia from '@/Shenghuohui/Showdata/Pingjia.vue'
import liuchengtu from '@/components/Liuchengtu.vue'
export default {
  components: {
    pdf,
    Pdfviewer,
    optformJieguo,
    optform,
    FangAn,
    ZhiXing,
    Huiqian,
    Huishang,
    Huihou,
    Fujian,
    Pingjia,
    liuchengtu
  },
  watch: {
    // 应该改为localStorage或直接传参数处理，目前用的方法可能会造成vuex和localStorage不同步，下次做民主生活会时应修改
    '$store.state.link1' (val) {
      console.log('link1' + this.$store.state.link1)
      console.log('activeNameold' + this.activeName)
      this.activeName = this.$store.state.link1
      console.log('activeNamenew' + this.activeName)
      this.getAllData()
    }
  },
  data () {
    return {
      pdfpage: 1,
      shenghuohui: {
        UnitName: '',
        ShenghuohuiId: '',
        ShenghuohuiName: ''
      },
      listLoading: false,
      totalnum: 0,
      startBtnsVisible: false,
      startLoading: false,
      Sortkey: '',
      Isace: true,
      Steps: [],
      OperationMsg: '',
      activeName: 'Huiqian',
      activeNameHuihou: 'bzzgqd',
      optForm: {},
      optFormLoading: false,
      jieguooptions: [],
      optFormRules: {
        Jieguo: [
          { required: true, message: '请选择处理结果', trigger: 'blur' }
        ]
      },
      IsOperationUser: false,
      CanBack: false,
      FangAnVisible: false,
      ZhixingVisible: false,
      PingguVisible: false,
      showFangan: false,
      showZhiXing: false,
      IsFinished: false,
      banzi: [],
      banzilistLoading: false,
      huiqiantimestamp: '',
      huishangtimestamp: '',
      huihoutimestamp: '',
      fujiantimestamp: '',
      shenghuohuinameshow: false,
      fileList: [],
      pingjiatimestamp: '',
      basesrc: '',
      lctVisible: false,
      caozuoVisible: false,
      fangantimestamp: '',
      caozuotimestamp: '',
      Operation: '',
      liuchengtutimestamp: '',
      HaveHuiYiData: false
    }
  },
  methods: {
    uploadfinish () {
      this.getUnitDetails()
    },
    caozuofinish () {
      this.caozuoVisible = false
      this.getUnitDetails()
    },
    Fanganshow () {
      this.FangAnVisible = true
    },
    Zhixingshow () {
      this.ZhixingVisible = true
    },
    Pinggushow () {
      this.PingguVisible = true
    },
    showLct () {
      this.liuchengtutimestamp = new Date().getTime()
      this.lctVisible = true
    },
    showCaozuo () {
      this.caozuoVisible = true
    },
    pdfshow () {
      this.pdfpage = 1
      console.log('pdfpage' + this.pdfpage)
      this.showPDFVisible = true
      this.pdfviewersrc = this.basesrc + new Date()
    },
    getAllData () {
      if (this.activeName === 'Huiqian') {
        this.huiqiantimestamp = new Date().getTime()
      }
      if (this.activeName === 'Huishang') {
        this.huishangtimestamp = new Date().getTime()
      }
      if (this.activeName === 'Huihou') {
        this.huihoutimestamp = new Date().getTime()
      }
      if (this.activeName === 'Fujian') {
        this.fujiantimestamp = new Date().getTime()
      }
      if (this.activeName === 'Pingjia') {
        this.pingjiatimestamp = new Date().getTime()
      }
    },
    tabClick () {
      this.getAllData()
      var params = {Link1: this.activeName}
      this.$store.commit('tablink1', params)
    },
    getUnitDetails () {
      this.startBtnsVisible = false
      var _this = this
      this.listLoading = true
      let para = {
        id: this.$route.params.id
      }
      // var personParams = { Page: 0, Pagenum: 20, Personname: '', Unitkey: '', Sortkey: '', Isace: true, timestamp: new Date().getTime() }
      this.$http
        .post(`/shenghuohui/unitdetails`, para)
        .then(function (response) {
          _this.listLoading = false
          if (response.data.IsSuccess === true) {
            console.log('获取成功')
            _this.shenghuohui = response.data.Shenghuohui
            _this.OperationMsg = response.data.OperationMsg
            _this.WorkFlow = response.data.WorkFlow
            _this.fileList = response.data.fileList
            _this.fangantimestamp = new Date().getTime()
            _this.caozuotimestamp = new Date().getTime()
            _this.liuchengtutimestamp = new Date().getTime()
            _this.IsOperationUser = response.data.IsOperationUser
            _this.IsFinished = response.data.IsFinished
            _this.shenghuohuinameshow = response.data.IsAdmin
            _this.Operation = response.data.Operation
            _this.HaveHuiYiData = response.data.HaveHuiYiData
            // if (_this.IsOperationUser === true) {
            //   _this.activeName = 'Caozuo'
            //   if (response.data.Operation.indexOf('FangAn') > -1) {
            //     _this.showFangAn = true
            //   } else {
            //     _this.showFangAn = false
            //   }
            //   if (response.data.Operation.indexOf('ZhiXing') > -1) {
            //     _this.showZhiXing = true
            //   } else {
            //     _this.showZhiXing = false
            //   }
            // } else {
            //   _this.activeName = 'AllData'
            // }
            _this.CanBack = response.data.CanBack
            _this.getAllData()
            console.log('获取总数:' + response.data.Msg)
            console.log('获取size:' + _this.pagenum)
            _this.totalnum = parseInt(response.data.Msg)
          } else {
            console.log('获取失败:' + response.data.Msg)
            _this.$message({
              message: '获取失败:' + response.data.Msg,
              type: 'error'
            })
          }
        })
        .catch(function (error) {
          console.log(error)
          _this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
          _this.listLoading = false
        })
    }
  },
  mounted () {
    this.getUnitDetails()
    var params = {Link1: 'Huiqian'}
    this.$store.commit('tablink1', params)
    var paramsHq = {Link_hq: 'Fangan'}
    this.$store.commit('tablink_hq', paramsHq)
    var paramsHz = {Link_hz: 'HS_HuiYiYiCheng'}
    this.$store.commit('tablink_hz', paramsHz)
    var paramsHh = {Link_hh: 'HH_BanZiZhengGai'}
    this.$store.commit('tablink_hh', paramsHh)
  }
}
</script>
<style scoped>
#Shenghuohui{
  padding: 20px
}
</style>
<style>
#Shenghuohui .el-tabs__item.is-active{
    color: #fff !important;
    background: #0058AC;
}
#Shenghuohui .el-tabs__item is-left{
  width:50px;
}
</style>
